class AppError extends Error {
  constructor(message, statusCode) {
    super(message)

    this.statusCode = statusCode
    this.status = `${statusCode}`.startsWith('4') ? 'failed' : 'error'
    this.isOperational = true // 标记这个错误是可预知的业务错误

    // 让错误信息更直观
    Error.captureStackTrace(this, this.constructor)

    // 修复prototype
    Object.setPrototypeOf(this, AppError.prototype)
  }
}

module.exports = AppError
